#define _CRT_SECURE_NO_WARNINGS
#include "game.h"

void menu()//打印菜单
{
	printf("***************************\n");
    printf("*******1.play 0.exit*******\n");
    printf("***************************\n");
}

void game()
{
    char ret = ' ';
    char arr[ROW][CLO] = { 0 };

    InitBoard(arr,ROW,CLO);
    DisplayBoard(arr, ROW, CLO);

    while (1)
    {
        PlayerMove(arr, ROW, CLO);
        DisplayBoard(arr, ROW, CLO);
        ret = Iswin(arr, ROW, CLO);
        if (ret == '*')
        {
            printf("玩家胜利\n");
                break;
        }
        if (ret == '#')
        {
            printf("电脑胜利\n");
            break;
        }
        if (ret == 'Q')
        {
            printf("游戏继续\n");
        }
        if (ret == 'C')
        {
            printf("平局\n");
            break;
        }


        CompurterMove(arr, ROW, CLO);
        DisplayBoard(arr, ROW, CLO);
        ret = Iswin(arr, ROW, CLO);
        if (ret == '*')
        {
            printf("玩家胜利\n");
            break;
        }
        if (ret == '#')
        {
            printf("电脑胜利\n");
            break;
        }
        if (ret == 'Q')
        {
            printf("游戏继续\n");
        }
        if (ret == 'C')
        {
            printf("平局\n");
            break;
        }
        
    }

}
int main()
{
    srand((unsigned int)time(NULL));//设置随机数的起点(产生随机种子)
    int input;
    do
    {
        menu();
        printf("请选择\n");
        scanf("%d", &input);
        switch (input)
        {
        case 1:
            game(); 
            break;
        case 0:
            break;
        default:
            printf("输入错误\n");
            break;
        }
    } while (input);
    return 0;
}